import axios from 'axios'
import { ElMessage } from 'element-plus'
import router from '../router/router'

const request = axios.create({
    baseURL:'http://121.89.205.189:3000/admin'
})

// 请求拦截
request.interceptors.request.use(req =>{
    req.headers.token = localStorage.getItem('token')
    return req
})

// 响应拦截
request.interceptors.response.use(res => {
    if(res.data.code !== '200') {
        ElMessage(res.data.message)
    }

    if(res.data.code === '10119') {
        router.push('/login')
    }

    return res.data
})

export default request